import requests

def get_weather(api_key, city):
    base_url = "https://restapi.amap.com/v3/weather/weatherInfo"
    parameters = {
        'key': api_key,
        'city': city,
        'extensions': 'base',  # 或 'all' 获取更详细的信息
        'output': 'json'
    }
    try:
        response = requests.get(base_url, params=parameters)
        data = response.json()['lives'][0]
        for x in data.values():
            print(x,end='\t')
        print('\n')

    except Exception as e:
        print(f"An error occurred: {e}")

# 替换为您的高德地图开发者密钥和城市名
amap_api_key = 'd53624e1eeb05e1f7c01832b35339345'
city_code = '310000'    #安仁：431028  长沙：430100  北京：110000  上海：310000

get_weather(amap_api_key, 431028)
get_weather(amap_api_key, 430100)
get_weather(amap_api_key, 110000)
get_weather(amap_api_key, 310000)

